﻿using System;
using System.Threading.Tasks;
using Thinker.SignChannel.Entities;
using Thinker.SignChannel.Repositories;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Content;

namespace Thinker.SignChannel.Results;

public class ResultAppService(
    IPersonTimeRepository personTimeRepository,
    PersonTimeCreator personTimeCreator,
    ResultBuilder resultBuilder) :
    SignChannelAppService, IResultAppService
{
    public Task<IRemoteStreamContent> ExportAsync(Guid timeId)
    {
        throw new NotImplementedException();
    }

    public Task<IRemoteStreamContent> ExportAllAsync()
    {
        throw new NotImplementedException();
    }

    public Task<PagedResultDto<ResultDto>> GetListAsync(ResultListInput input)
    {
        throw new NotImplementedException();
    }

    public async Task BuildAllAsync(Guid timeId)
    {
        await personTimeCreator.BuildAllAsync(timeId);
        await resultBuilder.CalcAllAsync(timeId);
    }

    public async Task<ResultDto> LeaveAsync(LeaveInput input)
    {
        var personTime = await personTimeCreator.GetOrCreateAsync(timeId: input.TimeId,
            personId: input.PersonId);
        personTime.LeaveReason = input.LeaveReason;
        personTime.SignResult = SignResult.Leave;
        await personTimeRepository.UpdateAsync(personTime, true);
        return MapToDto(personTime);
    }

    public Task<ListResultDto<ResultDto>> LeaveAfterAsync(LeaveInput input)
    {
        throw new NotImplementedException();
    }

    private ResultDto MapToDto(PersonTime personTime)
    {
        throw new NotImplementedException();
    }
}